﻿package imvu.rbox.struct
{
	import imvu.rbox.event.BoxEvent;
	import imvu.rbox.struct.boxes.*;
	
	public class BoxInfo extends Object
	{
		public var boxID:Number;		//	对象的编号
		public var boxData:BoxStruct;	//	对象的结构
		
		public function BoxInfo(num:Number = 0)
		{
			id = num;
			boxData = new BoxStruct();
		}
		
		public function set id(num:Number):void
		{
			boxID = Math.floor(num);
			// trace("setBoxID:" + boxID);
			
			switch(boxID)
			{
				// 2
				case BoxEvent.BOX_LEFT_L :
					boxData = new BoxLeftL();
					break;
				
				case BoxEvent.BOX_LEFT_S :
					boxData = new BoxLeftS();
					break;
				
				case BoxEvent.BOX_LEFT_Y :
					boxData = new BoxLeftY();
					break;
				
				case BoxEvent.BOX_LEFT_Z :
					boxData = new BoxLeftZ();
					break;
				
				// 1
				case BoxEvent.BOX_LINE :
					boxData = new BoxLine();
					break;
				
				case BoxEvent.BOX_REC :
					boxData = new BoxRectangle();
					break;
				
				// 3
				case BoxEvent.BOX_RIGHT_L :
					boxData = new BoxRightL();
					break;
				
				case BoxEvent.BOX_RIGHT_S :
					boxData = new BoxRightS();
					break;
				
				case BoxEvent.BOX_RIGHT_Y :
					boxData = new BoxRightY();
					break;
				
				case BoxEvent.BOX_RIGHT_Z :
					boxData = new BoxRightZ();
					break;
				
				case BoxEvent.BOX_T :
					boxData = new BoxFontT();
					break;
				
				case BoxEvent.BOX_U :
					boxData = new BoxFontU();
					break;
				
				case BoxEvent.BOX_X :
					boxData = new BoxFontX();
					break;
				
				case BoxEvent.BOX_BIG_T :
					boxData = new BoxBigFontT();
					break;
				
				case BoxEvent.BOX_L_THREE :
					boxData = new BoxLineThree();
					break;
				
				case BoxEvent.BOX_L_TWO :
					boxData = new BoxLineTwo();
					break;
				
				default :
					if(boxID > 0)
					{
						boxID = BoxEvent.BOX_FLY;
						boxData = new BoxFly();
					}
					break;
			}
			
			// trace("nowBoxData::" + this.boxData);
		}
		
		public function get id():Number
		{
			return this.boxID;
		}
		
		//	设置形状的方向编号
		public function set arrow(num:Number):void
		{
			if(this.boxData)
			{
				// trace("setArrow::" + num);
				this.boxData.id = num;
			}
		}
		
		public function get arrow():Number
		{
			if(this.boxData)
			{
				return this.boxData.id;
			}
			return -1;
		}
		
		public function toArray(isChange:Boolean = false):Array
		{
			var tArray:Array;
			
			if(this.boxData)
			{
				//**
				if(isChange)
				{
					tArray = this.boxData.toArray(this.boxData.id + 1);
				}
				else
				{
					tArray = this.boxData.toArray();
				}
			}	
			
			// trace("getChange::" + tArray);
			
			if(tArray)
			{
				for(var i:int = 0; i < tArray.length; i++)
				{
					for(var j:int = 0; j < tArray[i].length; j++)
					{
						if(tArray[i][j] == 1)
						{
							tArray[i][j] = this.boxID;
						}
					}
				}
			}
			
			// trace("GetArray::" + tArray);
			
			return tArray;
		}
	}
}